package zhtt01.mysql02.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zhtt01.mysql02.entity.User02;
import zhtt01.mysql02.repository.User02Repository;

/**
 * Created by zhtt on 2016/10/31.
 */
@RestController
@RequestMapping("user02")
public class User02Controller {

    @Autowired    private User02Repository dao;

    @RequestMapping("/get/{id}")
    private Object get(@PathVariable("id") int id) {
        try{
            return dao.getOne(id);
//            return "查询成功";
        }catch (Exception e){
            e.printStackTrace();
            return e.getMessage();
        }
    }

    @RequestMapping("/save/{name}/{email}")
    private Object save(@PathVariable("name") String name,@PathVariable("email") String email) {
        try{
            User02 user=new User02();
            user.setName(name);
            user.setEmail(email);
            dao.save(user);
            return "保存成功！";
        }catch (Exception e){
            e.printStackTrace();
            return e.getMessage();
        }
    }
}